

package com.ptppay.cf.coin.service.btc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.bitcoinj.wallet.Wallet;

import com.ptppay.cf.btc.CFBtc;

import cn.finder.bitcoin.BtcTools;
import cn.finder.ui.webtool.QueryCondition;
import cn.finder.wae.business.domain.Message;
import cn.finder.wae.business.domain.TableQueryResult;
import cn.finder.wae.business.dto.MapParaQueryConditionDto;
import cn.finder.wae.queryer.handleclass.QueryerDBAfterClass;

/**
 * @author: finder
 * @function:钱包余额查询  coin
 */
public class CreateKeyChainSeedTextAfterClass extends QueryerDBAfterClass {


    private Logger logger = Logger.getLogger(CreateKeyChainSeedTextAfterClass.class);

    @Override
    public TableQueryResult handle(TableQueryResult tableQueryResult,
                                   long showTableConfigId, QueryCondition<Object[]> condition) {
        super.handle(tableQueryResult, showTableConfigId, condition);
        logger.info("===" + this.getClass());
        @SuppressWarnings("unchecked")
        Map<String, Object> data = ((MapParaQueryConditionDto<String, Object>) condition).getMapParas();

        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();

        Map<String, Object> mapItem = new HashMap<String, Object>();
        tableQueryResult.setResultList(resultList);

        tableQueryResult.setPageIndex(condition.getPageIndex());
        tableQueryResult.setPageSize(condition.getPageSize());
        tableQueryResult.setCount(1l);


        resultList.add(mapItem);




        String coin_type = "BTC";
       /* try {
            coin_type = data.get("coin_type").toString();
        } catch (Exception e) {
            tableQueryResult.getMessage().setResultCode(Message.StatusCode_PARAMS_ERROR);
            tableQueryResult.getMessage().setResultMsg("param [coin_type] is error");
        }*/
        
      /*  User user=(User)data.get("session_user");
        if(user==null){
        	 errorReturn(tableQueryResult, Message.StatusCode_PARAMS_ERROR, "param session_user is err");
        }*/
    	
        String wallet_id=data.get("wallet_id").toString();
        
    	if(tableQueryResult.getMessage().getResultCode()==Message.StatusCode_OK){
    		try{
    			
    			CFBtc cfbtc=new CFBtc();
    			Wallet wallet=cfbtc.getWallet(wallet_id);
    			
				String seeds=BtcTools.createKeyChainSeedText(wallet);
           		
				mapItem.put("seeds", seeds);
				
			

				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				tableQueryResult.getMessage().setResultCode(Message.StatusCode_ServerError);
				tableQueryResult.getMessage().setResultMsg("create keychain seeds error");
			}
    		
    	}
		
       
		return tableQueryResult;
		 
	}

    private TableQueryResult errorReturn(TableQueryResult tableQueryResult, int resultCode, String msg) {
        tableQueryResult.getMessage().setResultCode(resultCode);
        tableQueryResult.getMessage().setResultMsg(msg);
        tableQueryResult.getMessage().setMsg(msg);
        return tableQueryResult;
    }
	@Override
	public void setJDBCDataSource(DataSource dataSource) {
		super.setJdbcDataSource(dataSource);
	}

	

}
